package cn.dmp.util

import org.apache.spark.sql.Row

/**
  * Created by Administrator on 2018/4/22.
  */
object AdApi {

  def apply(row:Row)={
  val pName = row.getAs[String]("provincename")
  val cName = row.getAs[String]("cityname")
  val rMode = row.getAs[Int]("requestmode")
  val pNode = row.getAs[Int]("processnode")
  val iseff = row.getAs[Int]("iseffective")
  val isbil = row.getAs[Int]("isbilling")
  val isbid = row.getAs[Int]("isbid")
  val adord = row.getAs[Int]("adorderid")
  val iswin = row.getAs[Int]("iswin")
  val winprice = row.getAs[Double]("winprice")
  val adpayment = row.getAs[Double]("adpayment")

  //原始请求 有效请求 广告请求 判断
  val adRe = if(rMode==1){
    if (pNode==1){
      List[Double](1,0,0)
    }else if (pNode==2){
      List[Double](1,1,0)
    }else if (pNode==3){
      List[Double](1,1,1)
    }else List[Double](0,0,0)
  }else {
    List[Double](0, 0, 0)
  }

  //参与竞价和成功竞价
  val adRtb = if(iseff==1 && isbil==1){
    if (isbid==1 && adord !=0) List[Double](1,0) else List[Double](0,0)
    if (iswin==1) List[Double](0,1) else List[Double](0,0)
  }else{List[Double](0,0)}

  //展示点击
  val ad3= if(iseff==1){
    if (pNode==2) List[Double](1,0) else List[Double](0,0)
    if (pNode==3) List[Double](0,1) else List[Double](0,0)
  }else List[Double](0,0)

  //消费成本
  val ad4= if(iseff==1&& isbil==1 && iswin==1) {
    List[Double](winprice/1000,adpayment/1000)
  }else List[Double](0,0)

  ((pName,cName), adRe++adRtb ++ ad3 ++ ad4)
}
}
